var krpano = document.getElementById('krpanoSWFObject');
var media = document.getElementById('audio');
var weixinBrowser=false;
var initBrowser=0;

var userid = 0;
/*if (objSite.isLogin()) {
  var userInfo = $.cookie('userCookieData');
  if (!userInfo || userInfo === 'null') {
    userid = 0;
  } else {
    var obj = JSON.parse(userInfo);
    userid = obj.user_id;
  }
} else {
  userid = 0;
}*/

// window.οnlοad=function(){

// 	if(media){
// 		media.play();
// 	} 
// }

window.onload = function () {
	if(window.sessionStorage.getItem('is_reload_for_gyro')) {
		krpano.call("set(layer[gyrobuttonClose].visible, true)");
		krpano.call("set(layer[gyrobutton].visible, false)");
		krpano.call("switch(plugin[gyro].enabled);");
	}
}

function ios13granted(cb) {
	if (typeof DeviceMotionEvent.requestPermission === 'function') {
		DeviceMotionEvent.requestPermission().then((permissionState) => {
			if (permissionState === 'granted') {
				window.addEventListener('devicemotion', () => {

				});
				cb && cb()
			}
		}).catch((error) => {

		})
	} else {
		cb && cb()
	}
}
$(function(){
	if($('#offlineInput').val() != 0) {
		// 获取当前url地址
		let iframeUrl = window.location.href;
		let domainName = "";
		// 判断是否在本域名环境下
		if(parent !=window){
			domainName = document.referrer;
		}else{
			domainName = window.parent.document.URL;
		}
		let key = iframeUrl.split("_");
		/* if(!domainName.includes(objSite.vr_domain) && !domainName.includes(objSite.work_domain)){
			if(key[key.length-1].split(".")[0].length != 32){
				let html = "<div class='iframe-mask'></div>";
				$("body").append(html)

			}
		} */
		var ua = navigator.userAgent.toLowerCase();
		if(ua.match(/MicroMessenger/i)=="micromessenger") {
			//ios的ua中无miniProgram，但都有MicroMessenger（表示是微信浏览器）
			wx.miniProgram.getEnv((res)=>{
				if (res.miniprogram) {
					if(key[key.length-1].split(".")[0].length != 32){
						let html = "<div class='iframe-mask'></div>";
						$("body").append(html)
					}
				}
			})
		}
	}
})
document.addEventListener('DOMContentLoaded', function () {
    if (media&&GetQueryString('is_home')!=1) {
        function audioAutoPlay() {
			var audio = document.getElementById('audio');
            audio.play();
            document.addEventListener("WeixinJSBridgeReady", function () {
                audio.play();
            }, false);
			document.addEventListener("YixinJSBridgeReady",function() {
                audio.play();
            },false);
        }
        audioAutoPlay();
	}
});



	 $(document).ready(function () {
		if (media&&GetQueryString('is_home')!=1) {
			var initMouseover=0;
			$("body").click(function () {
				if(initBrowser==0){
					media.play();
				}
				initBrowser=1;
			});
			$("body").mouseover(function(){
				if(initBrowser==0){
					media.play();
				}
				initBrowser=1;
			});
		　　$(document).keydown(function(event){
			　　if(initBrowser==0){
					media.play();
				}
				initBrowser=1;
		　　});
			$('body').on('touchstart', function () {
				　if(initBrowser==0){
					media.play();
				}
				initBrowser=1;
			});
			//手指在屏幕上移动时触发
			$('body').on('touchmove', function (even) {
				　if(initBrowser==0){
					media.play();
				}
				initBrowser=1;
			});
		}
	});


function checkout_icon() {
	initBrowser=1;
	var media = document.getElementById("audio");
	if(!krpano){
		krpano = document.getElementById('krpanoSWFObject');
	}
	if (krpano.get("layer[set_music_icon].bgalpha") == "1") {
		krpano.set("layer[set_music_icon].bgalpha", 0.6);
		krpano.set("layer[set_music_icon].url", objSite.getStaticUrl('/vr/images/pano-icon-1s.png'));
		// if(weixinBrowser){

			media.pause();
		// }
	} else {
		krpano.set("layer[set_music_icon].bgalpha", 1);
		krpano.set("layer[set_music_icon].url", objSite.getStaticUrl('/vr/images/pano-icon-1.png'));
		// if(weixinBrowser){

			media.play();
		// }
	}

}
// document.addEventListener('DOMContentLoaded', function () {
// 	var audio = document.getElementById('audio');
// 	function audioAutoPlay() {

// 		audio.play();
// 		document.addEventListener("WeixinJSBridgeReady", function () {
// 			audio.play();
// 		}, false);
// 	}
// 	if(audio){
// 		audioAutoPlay();
// 	}
// });
function icon_none() {
	// $(".right-bottom").hide();
}

function icon_show() {
	$(".right-bottom").show();

}
// 自动切换后给对应场景改样式
function automaticSwitching(){
	var krpanoSwitching = document.getElementById('krpanoSWFObject');
	var sceneId= krpanoSwitching.get("xml.scene").split('_');
	if($('.panos_anim .panos_wrapper>div[data-name="'+sceneId[1]+'"]').length!=0){
		$('.panos_anim .panos_wrapper>div[data-name="'+sceneId[1]+'"]').addClass('active').siblings().removeClass('active');
	}else{
		$('.panos_anim .panos_wrapper>div').removeClass('active');
	}

}

function openurl(url) {
	// setIsEditHotSpot()
	// if (isEditHotSpot) {
	//     return
	// }

	window.open(url)
}

// 视频播放
function openVideo(url) {
	// 插入iframe
	$('body').append('<div class="bg-mask"></div>' +
		'<div class="layer-video-box">' +
		'<div class="layer-video-content">' +
		'<div class="layer-video">' +
		'<button class="layer-video-close" type="button"></button>' +
		'<iframe src="' + url + '" allowfullscreen="true" scrolling="no" border="0" frameborder="0"></iframe>' +
		'</div>' +
		'</div>' +
		'</div>');
		if(media){
			media.pause();
		}

	// 关闭播放
	$(document).on('click', '.layer-video-close', function () {
		$('.bg-mask,.layer-video-box').remove();
		if(media){
			media.play();
		}
	});
}
var vr_id=$('#vr-index-detail-id').val();
//预览 +1
/* $.post('/vr/get_vr_info/addVrViews', {
	vr_id: vr_id
}); */

//预览日志记录 +1
/* $.post('/vr/get_vr_info/addVrLog', {
	vr_id: vr_id
}); */

// 顶部广告
/* $('.top-focus').liMarquee({
	direction: 'left',
	runshort: true,
	scrollamount: 60
}); */

if($('.panos_itemActive.active .marquee_default').text().trim().length > 10){
	panosNmaeliMarquee();
}

function panosNmaeliMarquee() {
    // 场景图名称
    $('.panos_itemActive.active').find(".marquee_default").liMarquee({
        direction: 'left',
        runshort: true,
        scrollamount: 30
    });
}

// 二维码
$('.link-qrcode').qrcode({
	render: 'canvas',
	width: 180,
	height: 180,
	text: location.href
});
/*jxl:加入二维码*/
//$('.link-qrcode').css('display', 'block');
/* var canvas = $('.link-qrcode').find("canvas")[0];
try { //解决IE转base64时缓存不足，canvas转blob下载
	var blob = canvas.msToBlob();
	navigator.msSaveBlob(blob, 'qrCode' + '.png');
} catch (e) { //如果为其他浏览器，使用base64转码下载
	var url = canvas.toDataURL('image/jpeg');
	$("#showCanvasImg").attr("download", 'qrCode' + '.png')
	$("#showCanvasImg").attr('src', url).get(0).click();
} */

// $('.right-bottom li >i,.right-bottom li >span').on('click', function (e) {
// 	e.stopPropagation()
// 	$(this).siblings('div').toggle();
// });


function isThisMobile() {

	return navigator.userAgent.toLowerCase().match(/(ipod|ipad|iphone|android|coolpad|mmp|smartphone|midp|wap|xoom|symbian|j2me|blackberry|wince)/i) != null;
}
/*jxl:加入隐藏显示按钮*/
function isMobile() {
	var is_mobi = navigator.userAgent.toLowerCase().match(/(ipod|ipad|iphone|android|coolpad|mmp|smartphone|midp|wap|xoom|symbian|j2me|blackberry|wince)/i) != null;
	if (is_mobi) {
		// console.log(krpano.get("layer[leftbottom_bar].visible"));
		$('.right-bottom li.hide-li').show();
		krpano.set("layer[set_full].visible", false);

		krpano.set("layer[right_bar].x", -5);

		krpano.set("layer[set_scene].width", 30);
		krpano.set("layer[set_scene].height", 30);
		krpano.set("layer[set_scene_txt].css", 'font-family:微软雅黑; font-size:12px; color:#fff;');
		krpano.set("layer[set_scene_txt].y", 25);
		krpano.set("layer[leftbottom_bar].y", 20);
		krpano.set("layer[leftbottom_bar].x", 10);

		krpano.set("layer[set_music_icon].width", 30);
		krpano.set("layer[set_music_icon].height", 30);
		krpano.set("layer[set_music_txt].css", 'font-family:微软雅黑; font-size:12px; color:#fff;');
		krpano.set("layer[set_music_txt].y", 25);

		krpano.set("layer[set_vr_icon].width", 30);
		krpano.set("layer[set_vr_icon].height", 30);
		krpano.set("layer[set_vr_txt].css", 'font-family:微软雅黑; font-size:12px; color:#fff;');
		krpano.set("layer[set_vr_txt].y", 25);

		krpano.set("layer[watermark].width", 100);
		krpano.set("layer[watermark].height", 25);

		krpano.set("layer[user_logo].width", 25);
		krpano.set("layer[user_logo].height", 25);

		krpano.set("layer[vr_title].css", "font-family:微软雅黑; font-size:14px;color:#FFFFFF; line-height:25px;width:auto;display:inline-block;");

	}
}


$('.right-bottom li.hide-li').on('touchend', function (e) {
	//console.log('touchend',isMobile());

})

// 开启清屏
var isfg = false;
var isClear = false;
var floorPlanOpen = 'block';
$('.clear-position').on('click',function () {
	var krpano = document.getElementById('krpanoSWFObject');
	isfg = true
	$(this).hide();
	$('.bottom-clear').show();
	//隐藏掉所有的其他按钮
	$('.right-bottom').hide();
	if($('.floor-planDetail-container').hasClass('open')){
		$('.floor-planDetail-container').removeClass('open');
	}else{
		floorPlanOpen = $('.floor-planDetail-openWrap').css('display')
	}
	$('.floor-planDetail-openWrap').hide();
	krpano.set("layer[left_bar].visible", false);
	krpano.set("layer[right_bar].visible", false); //right_bar ,leftbottom_bar
	krpano.set("layer[topleft_bar_right].visible", false);
	// krpano.set("layer[leftbottom_bar].visible", false);
	krpano.set("layer[set_scene_homepage].visible", false);
	krpano.set("layer[set_scene_txt_homepage].visible", false);
	krpano.set("layer[set_scene_txt].visible", false);
	$('.top-focus').hide();
	window.sessionStorage.setItem('is_open_clear', '1')

	//krpano.set("scene.visible",false);
	// krpano.call("skin_showthumbs(false)");
	buriedNewLog({
		buried_type:"click_vr_res_details_page_btn",
		vr_res_details_page_btn_content:11
	});
});
// 关闭清屏
$(document).on('click', '.bottom-clear', function(){
	isfg = false
	var krpano = document.getElementById('krpanoSWFObject');
	$('.right-bottom li.hide-li').show();
	$('.bottom-clear').hide();
	//显示出其他所有按钮
	//krpano.call("skin_showthumbs()");
	$('.clear-position').show();
	$('.right-bottom').show();
	$('.sharemg-icon').hide();
	// if(floorPlanOpen === 'block') {
	// 	$('.floor-planDetail-openWrap').show();
	// } else{
	// 	$('.floor-planDetail-openWrap').hide();
	// }
	$('.top-focus').show();
	krpano.set("layer[left_bar].visible", true);
	krpano.set("layer[right_bar].visible", true);
	krpano.set("layer[topleft_bar_right].visible", true);
	krpano.set("layer[set_scene_txt].visible", true);
	// krpano.set("layer[leftbottom_bar].visible", true);
	krpano.set("layer[set_scene_homepage].visible", true);
	krpano.set("layer[set_scene_txt_homepage].visible", true);
	krpano.set("layer[set_scene_txt].visible", true);

	window.sessionStorage.removeItem('is_open_clear')
	$('#floorDetailTrigger').trigger('click')

	// krpano.call("skin_showthumbs(true)");
});


//自定义分享内容
// var url = $('input[name="shareUrl"]').val();
// var vrName = $('input[name="vrName"]').val();
// var tel = $('input[name="tel"]').val();
// var isInfoShow = $('input[name="isInfoShow"]').val();
// // console.log(isInfoShow);
// var authorName = $('input[name="authorName"]').val();
// var img = $('input[name="vrImg"]').val();
// var isVip = $('input[name="isVip"]').val();
// var timelineName = $('input[name="vrName"]').val();
// if(isInfoShow == 1){
// 	if (isVip == 1 && tel && authorName) {
// 		authorName = authorName + '/' + tel;
// 		timelineName = authorName;
// 	}
// }else{
// 	// authorName = authorName + '/' + tel;
// 	timelineName = authorName;
// }
var WeixinFlag=false;
var url = $('input[name="shareUrl"]').val();
var vrName = $('input[name="vrName"]').val();
var tel = $('input[name="tel"]').attr('data-type')=='1'?$('input[name="tel"]').val():'';
// var isInfoShow = $('input[name="isInfoShow"]').val();
// console.log(isInfoShow);
// var authorName = $('input[name="authorName"]').attr('data-type')=='1'?$('input[name="authorName"]').val():'';
var authorName = $('input[name="authorName"]').val();
var img = $('input[name="vrImg"]').val();
var isVip = $('input[name="isVip"]').val();
// var timelineName =authorName!=''&&tel!=''?authorName+'/'+tel:authorName+tel;
authorName ? authorName =  authorName + "\n" : '';
var timelineName = authorName + $(".design-instructions-text").text().trim()
//微信分享
/* $.post('/vr/index_detail/getConfigSignature', {
	url: url
}, function (res) {

	// 配置微信
	wx.config({
		debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
		appId: res.appid, // 必填，公众号的唯一标识
		timestamp: res.timestamp, // 必填，生成签名的时间戳
		nonceStr: res.str, // 必填，生成签名的随机串
		signature: res.signature, // 必填，签名
		jsApiList: ['onMenuShareQQ', 'onMenuShareAppMessage', 'onMenuShareTimeline', 'checkJsApi','updateAppMessageShareData'] // 必填，需要使用的JS接口列表
	});
	wx.ready(function () { //需在用户可能点击分享按钮前就先调用
		WeixinFlag=true;
		// var u = navigator.userAgent;
		// var ua = u.toLowerCase();
		// // 判断是否是ios，如果是就自动音乐
		// if (/iphone|ipad|ipod/.test(ua)&&media) {
		// 	weixinBrowser=true;
		// 	media.play();
		// }timelineName
		wx.onMenuShareQQ({
			title: vrName, // 分享标题
			desc: timelineName, // 分享描述
			link: url, // 分享链接
			imgUrl: img, // 分享图标
			success: function () {},
			cancel: function () {}
		});
		wx.onMenuShareAppMessage({
			title: vrName, // 分享标题
			desc:timelineName, // 分享描述
			link: url, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
			imgUrl: img, // 分享图标
			success: function () {

			}
		});
		wx.onMenuShareTimeline({
			title: vrName, // 分享标题
			// desc: '3', // 分享描述
			link: url, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
			imgUrl: img, // 分享图标
			success: function () {
				// 用户点击了分享后执行的回调函数

			}
		})
		//新接口，分享到朋友或QQ都可以（1.4.0版本,低的不行）
		// wx.updateAppMessageShareData({
		// 	title: vrName, // 分享标题
		// 	desc: timelineName, // 分享描述
		// 	link: url, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
		// 	imgUrl: img, // 分享图标
		// 	success: function () {
		// 		// 设置成功
		// 	}
		// })

	});
	//QQ分享
	// setShareInfo({
	// 	title: vrName, // 分享标题
	// 	summary: timelineName, // 分享内容
	// 	pic: img, // 分享图片
	// 	// url: url, // 分享链接
	// 	WXconfig: {
	// 		swapTitleInWX: true, // 是否标题内容互换（仅朋友圈，因朋友圈内只显示标题）
	// 		appId: res.appid, // 公众号的唯一标识
	// 		timestamp: res.timestamp, // 生成签名的时间戳
	// 		nonceStr: res.str, // 生成签名的随机串
	// 		signature: res.signature // 签名
	// 	}
	// });
}) */


//密码访问
$('#access-btn').click(function () {
	var pwd = $('input[name="pwd"]').val();
	var id = $(this).data('id');
	if (!pwd) {
		layer.msg('请输入正确的密码~');
		return false;
	}
	var url = '/vr/index_detail/checkPassWord';
	$.post(url, {
		pwd:pwd,
		id: id
	}, function (res) {
		if (!res.code) {
			layer.msg(res.msg);
		} else {
			$('.input-pwd-box-body').css('display', 'none');
			$('.right-bottom').css('display', 'block');
			embedpano({
                swf: $('#embedpano_swf').val(),
                xml: $('#embedpano_xml').val(),
                target: "pano",
                html5: "auto",
                mobilescale: 1.0,
                passQueryParameters: true,
                wmode: "opaque",
                bgcolor: "#FFFFFF",
                consolelog:true,
            });
		}
	})
});
// 热点图片预览
// function hotspotViewImgPreview(image){
// 	// if (WeixinFlag) {
// 	// 	wx.previewImage({
// 	// 		current: image,//当前显示图片的http链接，我这边是把图片转成了base64
// 	// 		urls: [image] //需要预览的图片http链接列表
// 	// 	});
// 	// } else {
// 		var data = []
// 		for (var i = 0; i < arguments.length; i++) {
// 			data.push({
// 				src: arguments[i]
// 			})
// 		}
//
// 		layer.photos({
// 			closeBtn: 1,
// 			photos: {
// 				start: 0,
// 				data: data
// 			},
// 			anim: 5, //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
// 			success: function () {
// 				$(".layui-layer-phimg img").on("contextmenu", function () {
// 					return false;
// 				});
// 				// $('#pano').hide();
// 				$('.layui-layer-imgbar').remove();
// 				changeImg2();
//
// 			}
// 		});
// 	// }
//
// }

// 热点图片预览
function hotspotImgPreview(imgName){
	if(WeixinFlag){
		wx.previewImage({
			current: imgName,//当前显示图片的http链接，我这边是把图片转成了base64
			urls: [imgName] //需要预览的图片http链接列表
		});
	}else{
		var data={
			"title": "测试", //相册标题
			"id": 123, //相册id
			"data": [   //相册包含的图片，数组格式
				{
					"alt": "图片名",
					"pid": 666, //图片id
					"src": imgName, //原图地址
					"thumb": "" //缩略图地址
				}
			]
		}

		layer.photos({
			closeBtn:1,
			photos: data,
			anim: 5, //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
			success: function() {
				$(".layui-layer-phimg img").on("contextmenu", function() {
					return false;
				});
				// $('#pano').hide();
				$('.layui-layer-imgbar').remove();
				changeImg2();

			}
		});
	}


}

function changeImg2() {
	var $targetObj = $('.layui-layer-photos .layui-layer-phimg img');
	cat.touchjs.init($targetObj, function(left, top, scale, rotate) {
		$targetObj.css({
			left: left,
			top: top,
			'transform': 'scale(' + scale + ')',
		});
	});
	cat.touchjs.drag($targetObj, function(left, top) {});
	cat.touchjs.scale($targetObj, function(scale) {});
}
$(document).on("mousewheel DOMMouseScroll", ".layui-layer-phimg img", function(e) {
    var delta = (e.originalEvent.wheelDelta && (e.originalEvent.wheelDelta > 0 ? 1 : -1)) || // chrome & ie
        (e.originalEvent.detail && (e.originalEvent.detail > 0 ? -1 : 1)); // firefox
    var imagep = $(".layui-layer-phimg").parent().parent();
    var image = $(".layui-layer-phimg").parent();
    var h = image.height();
    var w = image.width();
    if(delta > 0) {

            h = h * 1.05;
            w = w * 1.05;

    } else if(delta < 0) {
        if(h > 100) {
            h = h * 0.95;
            w = w * 0.95;
        }
    }
    imagep.css("top", (window.innerHeight - h) / 2);
    imagep.css("left", (window.innerWidth - w) / 2);
    image.height(h);
    image.width(w);
    imagep.height(h);
    imagep.width(w);
});

$('.icon-map').click(function(){
	var default_lng=$('.default_lng').val();
	var default_lat=$('.default_lat').val();
	var $width=$(window).width()>760?760+'px':$(window).width()-40+'px';

	// $('.design-instructions-text').hide()
	// $('.bottom-contact-show').hide()
	// $('.link-qrcode').hide()

	layer.open({    // closeBtn:1,
		type: 1,
		// skin: 'layui-layer-rim', //加上边框
		area: [$width, '450px'], //宽高
		content: $('.map-positioning'),
        title:'Ta的地图足迹',

        success:function(){
			var map = new BMap.Map("container");    // 创建Map实例
			var point = new BMap.Point(default_lng,default_lat);
			map.centerAndZoom(point, 15);  // 初始化地图,设置中心点坐标和地图级别
			map.setCurrentCity("北京");
			// 设置地图显示的城市 此项是必须设置的
			// var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT});// 左上角，添加比例尺
			// var top_left_navigation = new BMap.NavigationControl();  //左上角，添加默认缩放平移控件
			var top_right_navigation = new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_ANCHOR_TOP_LEFT}); //右上角，仅包含平移和缩放按钮
			/*缩放控件type有四种类型:
			BMAP_NAVIGATION_CONTROL_SMALL：仅包含平移和缩放按钮；BMAP_NAVIGATION_CONTROL_PAN:仅包含平移按钮；BMAP_NAVIGATION_CONTROL_ZOOM：仅包含缩放按钮*/
			//添加控件和比例尺
			map.addControl(top_right_navigation);
			var lngAndlat={};
			var marker = new BMap.Marker(point);// 创建标注
			map.addOverlay(marker);             // 将标注添加到地图中
			marker.enableDragging();            //可拖动
		}
	});
	buriedNewLog({//埋点
		buried_type:"click_vr_res_details_page_btn",
		vr_res_details_page_btn_content:"1"
	});
});
var wrapper_active_id=$('.panos_wrapper>div.active').data('name');
// 场景切换
 
$('.panos_wrapper').on('click','.panos_itemActive',function(){
	var krpano = document.getElementById('krpanoSWFObject');
	wrapper_active_id=$(this).data('name');
	alert(wrapper_active_id)
	/**
	 * 保存当前场景ID，用于页面通讯,切换场景时，需要更新对应的户型图
	 */
	window.sessionStorage.setItem('vr_img_id', wrapper_active_id)
	$('#floorDetailTrigger').trigger('click')


	$(this).addClass('active').siblings().removeClass('active');
    krpano.call("loadscene('scene_" + $(this).data('name') + "', null, MERGE, get(blendmodes[crossblending].blend))");

	$(".str_move").parent('.marquee_default').liMarquee("destroy");
	if($(this).find(".marquee_default").text().trim().length > 5){
		panosNmaeliMarquee();
	}
});
$('.groupsText_wrapper>.groupsText_item').click(function(){
    $('.panos_anim').removeClass('panos_move');
    $(this).addClass('GroupsText_active_tvrbhb').siblings().removeClass('GroupsText_active_tvrbhb');
    var tip=$(this).data('tip');
    setTimeout(function(){
        var wrapperHtml="";
        for(var i=0;i<groupsTextJson[tip].length;i++){
			var wreClass=wrapper_active_id==groupsTextJson[tip][i].sceneName?'active':'';
            // wrapperHtml+='<div data-name="'+groupsTextJson[tip][i].sceneName+'" class="panos_itemActive '+wreClass+'" currentitem="false">\
            //                     <div class="panos_img"\
            //                         style="background-image: url('+groupsTextJson[tip][i].img+');">\
            //                         <div class="block-horizontal-layout block-justify-center block-align-center">\
            //                         <div class="marquee_default Marquee_fontSize12_1DMqtm">\
            //                                     '+groupsTextJson[tip][i].name+'</div>\
            //                         </div>\
            //                     </div>\
            //                 </div>';
			wrapperHtml += '<div class="width-16"></div>' +
				'<div title="' +  groupsTextJson[tip][i].name + '" data-name="' + groupsTextJson[tip][i].sceneName + '" class="panos_itemActive ' + wreClass +'" currentitem="false">' +
				'<div class="panos_img" style="background-image: url(' + groupsTextJson[tip][i].img + ');">' +
				'</div>' +
				'<div class="panos_name">' +
				'<div class="marquee_default Marquee_fontSize12_1DMqtm panos_name_label">' +
				groupsTextJson[tip][i].name +
				'</div>' +
				'</div>' +
				'</div>'
        };
        $('.panos_wrapper').html(wrapperHtml);
		automaticSwitching();
        $('.panos_anim').addClass('panos_move');
    },200);
});
// 打开场景
function open_skin_showthumbs(){

    if($('.theme_content').is('.theme_show')){
        $('.theme_content').removeClass('theme_show');
    }else{
        $('.theme_content').addClass('theme_show');
    }
}
// 初始化是否已经开启场景
function init_open_skin(){
	// if($('.theme_content').data('show')==1){
    //     $('.theme_content').addClass('theme_show');
    // }
}
if($('.temporary-pop-uptwindow').length!=0){
	setTimeout(function(){
		$('.temporary-pop-uptwindow').hide();
	},5000);
}

function skin_homepage(){
	buriedNewLog({
		buried_type:"click_vr_res_details_page_btn",
		vr_res_details_page_btn_content:4
});
	window.location.href = $('#user_id').val();
}
var openBooking=$(window).width()>555?['535px', '352px']:[$(window).width()-20+'px', '372px'];
// 预约
function appoin(){
	layer.open({
		type: 1,
		title: '在线预约',
		resize: false,
		area:openBooking,
		content: $('.layer-online-booking'),
	});
	buriedNewLog({
		buried_type:"click_vr_res_details_page_btn",
		vr_res_details_page_btn_content:2
});
}
function jsBuried() {
	buriedNewLog({
		buried_type:"click_vr_res_details_page_btn",
		vr_res_details_page_btn_content:3
	});
}

function gyroJsBuried() {
	buriedNewLog({
		buried_type:"click_vr_res_details_page_btn",
		vr_res_details_page_btn_content: 10
	});
}

function openGyro() {
	var u = navigator.userAgent;
	var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1;   //判断是否是 android终端
	var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);     //判断是否是 iOS终端

	if(isIOS && !window.sessionStorage.getItem('is_reload_for_gyro')) {
		ios13granted(function () {
			krpano.call("switch(plugin[gyro].enabled);");
			window.sessionStorage.setItem('is_reload_for_gyro', 1)
			window.location.reload()
		})
	} else {
		if(krpano.get("layer[gyrobuttonClose].visible")) {
			krpano.call("set(layer[gyrobuttonClose].visible, false)");
			krpano.call("set(layer[gyrobutton].visible, true)");
		} else {
			krpano.call("set(layer[gyrobuttonClose].visible, true)");
			krpano.call("set(layer[gyrobutton].visible, false)");
		}
		krpano.call("switch(plugin[gyro].enabled);");

	}
}

// 预约信息提交
$('.js-confirm-submission').click(function (e) {
	var appoin_load = layer.load(1);
	var vr_id = $(this).data('id');
	var appoin_name = $('.appoin_name').val();
	var appoin_tel  = $('.appoin_tel').val();
	var appoin_desc = $('.appoin_desc').val();
	$.ajax({
		url:'/vr/index_detail/addAppoinVr',
		data:{vr_id:vr_id,appoin_name:appoin_name,appoin_tel:appoin_tel,appoin_desc:appoin_desc},
		type:'post',
		success:function(res){
			if(res.code == 1){
				layer.msg(res.msg)
				// setTimeout(function() {parent.location.reload();}, 1000);
				setTimeout(function () {
					$('.layer-online-booking').find('input').each(function (index, elem) {
						$(elem).val('')
					})
					$('.layer-online-booking').find('textarea').each(function (index, elem) {
						$(elem).val('')
					})
					layer.closeAll()
				}, 1000)
			}
			else{
				layer.msg(res.msg)
				setTimeout(function() {layer.close(appoin_load);}, 1000);

			}

		}
	})
});

// if($('.panos_itemActive.active').attr('data-name')!=undefined){
//     krpano.call("loadscene('scene_" + $('.panos_itemActive.active').attr('data-name') + "', null, MERGE, get(blendmodes[crossblending].blend))");
// }
function switchScenes(name){
    $('.panos_wrapper .panos_itemActive[data-name="'+name+'"]').addClass('active').siblings().removeClass('active');
	setScenesActive(name)
}

function setScenesActive(vrImgId) {
	// groupsTextJson
	// console.log(vrImgId)
	// console.log(groupsTextJson)
	var groupKey
	var groupItem = {}
	var group = {}
	for (var key in groupsTextJson) {
		// console.log(key)
		for (var i = 0; i < groupsTextJson[key].length; i++) {
			// console.log(groupsTextJson[key][i].sceneName)
			if (groupsTextJson[key][i].sceneName == vrImgId) {
				groupKey = key
				group = groupsTextJson[key]
				groupItem = groupsTextJson[key][i]
			}
		}
	}
	$('.groupsText_wrapper .groupsText_item').each(function (index, elem) {
		$(elem).removeClass('GroupsText_active_tvrbhb')
		if ($(elem).data('tip') == groupKey) {
			$(elem).addClass('GroupsText_active_tvrbhb')
		}
	})
	$('.panos_wrapper .panos_itemActive').each(function (index, elem) {
		$(elem).removeClass('active')
		if ($(elem).data('name') == groupItem.sceneName) {
			$(elem).addClass('active')
		}
	})
}


// 全景详情页关闭后上报数据
$(window).unload(function(e){
		//参数也可以采用formData或blob形式
	// 	var params = new URLSearchParams({
	// 	view_url:window.location.href,
	// 	up_time: Math.floor(new Date().getTime() / 1000),
	// 	platform_type: platformType(2), //平台类型
	// 	product_name: 4, //产品名称
	// 	user_id: userid,
	// 	uid:$.cookie("Hm_lvt_bh_ud") || 0,
	// 	browser:navigator.userAgent.toLowerCase(),
	// 	os:platformType(1),
	// 	screen_width:window.screen.width,
	// 	screen_height:window.screen.height,
	// 	works_id:$("#vr-index-detail-id").val(),
	// 	buried_type:"click_vr_res_details_page_close"
	// })
	// 	var URL = objSite.service_domain +'/api/v1/buried/buriedNew';
	// 	navigator.sendBeacon(URL, params);
		closeBuried();
});

// if(platformType(1) != "2"){
// 	$(document).on('click','.js-click-event',function(){
// 		buriedNewLog({
// 			buried_type:"click_vr_res_details_page_btn",
// 			vr_res_details_page_btn_content:$(this).attr("data-type") == 1 ? 9 : 8
// 		});
// 	})
// 	var ua = navigator.userAgent.toLowerCase()
// 	let isAndroid = ua.indexOf('Android') > -1 || ua.indexOf('Adr') > -1
// 			if (isAndroid) {
// 	　　　　// 安卓　　
// 				 window.onbeforeunload = function (e) {
// 					e = e || window.event
// 					// 处理函数
// 					closeBuried();

// 					return ''
// 				}
// 			} else {
// 	　　　　// ios
// 				window.addEventListener('pagehide', myUnloadHandler, false)
// 					function myUnloadHandler () {
// 							// 处理函数
// 							if (ua.match(/micromessenger/i) != 'micromessenger') {
// 								closeBuried();
// 							}

// 					}
// 			}
// }

function closeBuried() {
	var params = new URLSearchParams({
		view_url:window.location.href,
		up_time: Math.floor(new Date().getTime() / 1000),
		platform_type: platformType(2), //平台类型
		product_name: 4, //产品名称
		user_id: userid,
		uid:$.cookie("Hm_lvt_bh_ud") || 0,
		browser:navigator.userAgent.toLowerCase(),
		os:platformType(1),
		screen_width:window.screen.width,
		screen_height:window.screen.height,
		works_id:$("#vr-index-detail-id").val(),
		buried_type:"click_vr_res_details_page_close"
	})
		var URL = objSite.service_domain +'/api/v1/buried/buriedNew';
		navigator.sendBeacon(URL, params);
}

// 全景详情页_悬浮图标弹出信息曝光时长
var timer = null;
var hoverFlag = true;
$(document).on('mouseover','.js-hover-event',function(){
	var hoverType = $(this).attr("data-type");
	var _this = $(this);
	hoverFlag = true;
	if(!timer){
		timer = setTimeout(function(){
			timer = null;
			if(!hoverFlag)return false;
			_this.removeClass("js-hover-event")
			buriedNewLog({
				vr_res_details_page_buoy_btn_content:hoverType,
				buried_type:"vr_res_details_page_buoy_information_browse_duration"
			})
		},2000);
	}
})
$(document).on('mouseleave','.js-hover-event',function(){
	hoverFlag = false;
})

// 访问详情页埋点
setTimeout(() => {
	var _referrer=''
	if(GetQueryString('mobile')){
		_referrer=decodeURIComponent(GetQueryString('mobile'))
	}else{
		_referrer=document.referrer || ''
	}
	buriedNewLog({
		buried_type:"visit_vr_res_details_page",
		refer:_referrer,
		url:window.location.href,
		access_link_type:window.location.href.indexOf("burn_after_reading") >= 0 ? 2 : 1,
		vr_res_details_page_source:GetQueryString("pageSource") || ''
	});
}, 3000);

// logo埋点
$(document).on('click','.js-user-logo',function(){
	buriedNewLog({
		buried_type:"click_vr_res_details_page_btn",
		vr_res_details_page_btn_content:5
});
})
// 标题埋点
$(document).on('click','.js-vr-title',function(){
	buriedNewLog({
		buried_type:"click_vr_res_details_page_btn",
		vr_res_details_page_btn_content:6
	});
})
// 作者名称埋点
$(document).on('click','.js-user-name',function(){
	buriedNewLog({
		buried_type:"click_vr_res_details_page_btn",
		vr_res_details_page_btn_content:7
	});
})

// 作品名称埋点
$(document).on('click','.js-vr-name',function(e){
	e.preventDefault()
	buriedNewLog({
		buried_type:"click_vr_res_details_page_btn",
		vr_res_details_page_btn_content:6
	});
  window.location.href = $(this).attr('href')

})


// 埋点
function buriedNewLog(obj,ajaxIndex) {
/* 	var presetObj = { //预置属性
			view_url:window.location.href,
			up_time: Math.floor(new Date().getTime() / 1000),
			platform_type: platformType(2), //平台类型
			product_name: 4, //产品名称
			user_id: userid,
			uid:$.cookie("Hm_lvt_bh_ud") || 0,
			browser:navigator.userAgent.toLowerCase(),
			os:platformType(1),
			screen_width:window.screen.width,
			screen_height:window.screen.height,
			works_id:$("#vr-index-detail-id").val() || $("#vrId").val(),
	};
	var parmas = $.extend(presetObj,obj);
	if(ajaxIndex == 2){
		var URL = objSite.service_domain +'/api/v1/buried/buriedNew';
		navigator.sendBeacon(URL, parmas);
	}else{
		$.ajax({
			url: objSite.getServiceUrl('/api/v1/buried/buriedNew'),
			type: 'post',
			data: parmas,
			async:false,
			xhrFields: {
					withCredentials: true
			},
			success: function(res){
			}
	})
	} */

}

// 获取平台类型
function platformType(index) {
	if (/Mobi|Android|iPhone/i.test(navigator.userAgent)) {
		// 当前设备是移动设备
		var u = navigator.userAgent;
		var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
    var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
		if(isAndroid)return index == 1 ? "0" : "4"
		if(isiOS)return index == 1 ? "1" : "4"
	}else{
		return "2"
	}
}
// 获取url参数
function GetQueryString (name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if (r != null) {
		//解决中文乱码
		return decodeURI(r[2]);
	}
	return null;
}

function toggleFullScreen() {
	if (!document.fullscreenElement) {
		document.documentElement.requestFullscreen();
	} else {
		if (document.exitFullscreen) {
			document.exitFullscreen();
		}
	}
}

function openVR() {
	$('.floor-planDetail-openWrap').hide()
	$('.floor-planDetail-wrap').hide()
	$('.right-bottom').hide()
	$('.clear-position').hide()
}

function exitVR() {
	$('#floorDetailTrigger').trigger('click')
	$('.right-bottom').show()
	$('.clear-position').show()
}